package com.wink.common;

import java.util.Date;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.google.gson.Gson;
//import com.wink.common.Identity;
import com.wink.service.CommunityServicesImpl;

@XmlRootElement(name = "publish")
@XmlAccessorType(XmlAccessType.FIELD)
public class Publish {	

	@XmlElement(name = "server")
	private String server;	
	
	@XmlElement(name = "port")
	private String port;
	
	
	public String getServer() {
		return server;
	}

	public void setServer(String server) {
		this.server = server;
	}

	public String getPort() {
		return port;
	}

	public void setPort(String port) {
		this.port = port;
	}
	
	public String toString() {
		StringBuffer sf = new StringBuffer();
		
		sf.append("<server> " + server);
		sf.append("<port> " + port);						
		return sf.toString();
	}
	
	public static String toJson(Publish publish) {
		Gson gson = new Gson();
		String json = gson.toJson(publish, Publish.class);
		System.out.println("---> publish: tojson  " + json);
		
		Publish retCh = gson.fromJson(json, Publish.class);
		return json;
	}
	
	public static Publish fromJson(String json) {
		Gson gson = new Gson();
		Publish retCh = gson.fromJson(json, Publish.class);
		System.out.println("---> publish: fromJson  " + retCh.toString());
		return retCh;
	}
	
	public static void main(String[] args) {
		// to String
		Publish c = new Publish();
		c.setServer("MyServer");
		c.setPort("2022");
		String json = new Publish().toJson(c);		
		
		Publish ch = new Publish();
		ch.fromJson(json); 
		
	}
	
}


